package com.btb.adapter.vo.request;

import static java.util.stream.Collectors.joining;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.btb.adapter.constant.Constants;
import com.btb.adapter.model.OffChain;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Data
@ToString
public class OffChainRequest {
	private Integer type;
	private String owner;
	private List<Long> list;
	public OffChain build(final String requestId) {
		String clientId = Optional.ofNullable(list)
				.orElseGet(ArrayList::new)
				.stream()
				.map(String::valueOf)
				.collect(joining(","));
		return OffChain.builder()
				.owner(owner)
				.type(type)
				.requestId(requestId)
				.clientId(clientId)
				.status(Constants.OFFCHAIN_STATUS)
				.build();
	}
}
